#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
//#include "modbus.h"
#include "public.h"
char dest[256];
void threadcreate(void);
void * mbPollThread(void *arg);

static void pollThreadcreate(void);
static const int idx[7]={0,1,2,3,4,5,6};

extern int nativeUartTreat(void);
extern void mbPollUartTreat(INT8U idx);
void *slavePollThread(void)
{
	pollThreadcreate();
    sleep(1);
    return 0;
}
void * mbPollThread(void *arg)
{
    INT8U num=*(INT8U *)arg;

    	DebugPrint("RS485 PORT %d CREATE \n",num);
    	if(num<7) mbPollUartTreat(num);
		DebugPrint("no data create to poll ,so RS485 PORT %d thread EXIT  \n",num);
    	pthread_exit((void *)0);
    	//DebugPrint("serialPath is %s\n",serialPath[num]);
    	//if(num==4) pthread_exit((void *)0);

    //return NULL;
}

void * nativeSlavePollThread(void *arg)
{
    int num=*(int *)arg;
	DebugPrint("num is %d\n",num);
	nativeUartTreat();

	pthread_exit((void *)0);
}
static void pollThreadcreate(void)
{
	int i;
	char rc;
    pthread_t thr[7];
	if(pthread_create(&thr[6],NULL,nativeSlavePollThread,(void *)&idx[6])!=0)
	{
		DebugPrint("create thread 6 failed1\n");
		return;
	}
     for(i=0;i<6;i++)
     {
			if(pthread_create(&thr[i],NULL,mbPollThread,(void *)&idx[i])!=0)
			{
				DebugPrint("create thread %d failed!\n",i);
				return;
			}
     }
}
